package Tools.ThreadPoolExecutor;

import NoLock.Atomic.AtomicInteger_;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
@Slf4j(topic = "c.FixedThreadPool")
public class FixedThreadPool {
    public static void main(String[] args) {
        ExecutorService pool = Executors.newFixedThreadPool(2, new ThreadFactory() {
            private AtomicInteger t = new AtomicInteger(1);

            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r, "YS-pool" + t.getAndIncrement());
            }
        });

        for (int i = 0; i < 10; i++) {
            int j =i+1;
            pool.execute(() -> {
                log.debug("{}",j);
            });
        }
    }
}
